<template>
  <view :class="[`${prefixCls}-redirect-container`]"> </view>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import { getStorageCache, removeStorageCache } from '@/common/cache'

export default {
  name: 'redirect',
  mixins: [],
  props: {},
  data() {
    return {}
  },
  // 侦听属性
  watch: {},
  // 计算属性
  computed: {
    ...mapGetters([]),
  },
  // 监听页面加载，该钩子被调用时，响应式数据、计算属性、方法、侦听器、props、slots 已设置完成
  async onLoad(options) {
    // #ifdef H5
    let event = ''
    if (options.login_code) {
      event = 'login'
      const { error } = await this.$Platform.useProvider().login(options.login_code)
      if (error === 0) {
        this.GetUserInfo()
      }
    }
    if (options.bind_code) {
      event = 'bind'
      const { error } = await this.$Platform.useProvider().bind(options.bind_code)
    }

    // 检测H5登录回调
    let redirectUrl = getStorageCache('redirectUrl')
    if (redirectUrl) {
      removeStorageCache('redirectUrl')
      location.replace(redirectUrl)
    } else {
      this.$ROUTE.go({ url: '/' })
    }
    // #endif
  },
  // 监听页面显示，页面每次出现在屏幕上都触发
  onShow() {},
  // 监听页面初次渲染完成，此时组件已挂载完成
  onReady() {},
  // 下拉刷新
  onPullDownRefresh() {},
  // 加载更多
  onReachBottom() {},

  created() {},
  mounted() {},
  destroyed() {},
  methods: {
    ...mapActions('user', ['GetUserInfo']),
  },
}
</script>

<style lang="scss" scoped>
.#{prefixCls('redirect-container')} {
  position: relative;
}
</style>
